<?php
/**
 * Table.php - 27 Oct 2008
 * 
 * Extension of the Zend_Db_Table class to configure a prefix for the table 
 * name. Can be given via the adapter config array as params[ 'dbtableprefix' ]
 * 
 * @author Kevin Breed
 */

require_once( 'Zend/Db/Table.php' ); 

class KB_Db_Table extends Zend_Db_Table
{
	/**
	 * Returns the tablename prefix
	 * 
	 * @return	string	the prefix of the table name
	 */
	public function getTablePrefix ()
	{
		$conf = $this->getAdapter()->getConfig();		
		return $conf[ 'dbtableprefix' ];
	}
	
	/**
	 * Overwrites parent function to prefix the table name
	 * 
	 * @return void
	 */
	protected function _setupTableName ()
	{		
		$newName = $this->getTablePrefix();
		$newName .= ( !$this->_name ) ? get_class( $this ) : $this->_name;
		
		$this->_name = $newName;
		
		parent::_setupTableName();
	}
}

?>